const recommendModule = require('../../modules/base/cosmeticsRecommend')

const qs = require('querystring')

class CosmeticsRecommendControllers {
  /**
   * 获取设置列表
   */
  static async getRecommendSet(ctx) {
    const req = qs.parse(ctx.request.url.split('?')[1])
    if (!req.total || !req.pagination) {
      ctx.body = {
        code: 416,
        msg: '缺少参数'
      }
    }
    const total = (await recommendModule.getRecommend({})).length
    const list = await recommendModule.getRecommend({
      raw: true,
      limit: +req.total,
      offset: +req.total * (req.pagination - 1),
      order: [
        ['active', 'DESC']
      ]
    })

    ctx.body = {
      code: 200,
      data: {
        list,
        total,
        pagination: req.pagination
      }
    }
  }
}

module.exports = CosmeticsRecommendControllers
